package com.jieshen.lesson2;

import com.jieshen.lesson2.utils.myAWTTools;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TextTest {
    public static void main(String[] args) {
        //启动
        new MyFrame();
    }
}

class MyFrame extends Frame{
    public MyFrame() {
        TextField textField = new TextField();
        add(textField);

        //监听文本框输入的文字
        MyTextActionListener myTextActionListener = new MyTextActionListener();
        //回车触发事件
        textField.addActionListener(myTextActionListener);
        //设置替换编码
        textField.setEchoChar('*');
        setVisible(true);
        pack();
        myAWTTools.windowClose(this);
    }
}

class MyTextActionListener implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        //获得一些资源
        TextField field = (TextField) e.getSource();//Object能向下转型
        //输入框中的文本
        String text = field.getText();
        System.out.println(text);
        //用户
        field.setText("");
    }
}
